﻿
SET QUOTED_IDENTIFIER ON
GO

SET ANSI_NULLS ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_StaffMove]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_StaffMove];
GO
CREATE PROCEDURE [dbo].[sproc_StaffMove] 
    -- @StaffIDS nvarchar(300),
    @xml xml,
    @NewPositionID int
/*

============================================================
功能:    批量移动员工所在职位
参数:
    @StaffIDS nvarchar(300)        :    被移动的ID集合
    @NewPositionID int        :    移动到的新的职位ID

============================================================

*/
AS
BEGIN
SET NOCOUNT ON

/*
 * XML format:
 * <staffs>
 *  <s id="" />
 * </staffs>
 */

update p 
set p.Position_ID = @NewPositionID
from dbo.UDS_Staff_In_Position p inner join @xml.nodes('/staffs/s') R(x) on p.Staff_ID = R.x.value('@id', 'int');

END
GO